package com.freewater.springboot.demo.aop.api.advices.afterthrow;

import com.freewater.springboot.demo.aop.api.advices.CalculateImpl;
import com.freewater.springboot.demo.aop.api.advices.CalculateService;
import org.springframework.aop.framework.ProxyFactory;

import java.rmi.RemoteException;

public class Main {
    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.addAdvice(new SimpleThrowing());
        proxyFactory.setTarget(new CalculateImpl());

        final CalculateService proxy = (CalculateService) proxyFactory.getProxy();
        try {
            proxy.divide(10, 0);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        proxyFactory = new ProxyFactory();
        proxyFactory.addAdvice(new SimpleThrowing());
        proxyFactory.setTarget(new RemoteService());

        try {
            RemoteService remoteService = (RemoteService) proxyFactory.getProxy();
            remoteService.doSomething("my params");
        } catch (RemoteException e) {
            System.out.println(e.getMessage());
        }
    }
}
